/**
 * 回访详情  初始化
 */
var ApprovalProcessAudit = {
    id: "ApprovalProcessAuditTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

var myDate = new Date();
var month;
var day;
if ((myDate.getMonth() + 1) < 10) {
    month = "0" + (myDate.getMonth() + 1);
} else {
    month = "" + (myDate.getMonth() + 1);
}
if (myDate.getDate() < 10) {
    day = "0" + myDate.getDate();
} else {
    day = "" + myDate.getDate();
}

/**
 * 初始化表格的列
 */
ApprovalProcessAudit.initColumn = function () {
    var columns = [
        {field: 'selectItem', radio: true},
        {title: '', field: 'id', visible: false, align: 'center', valign: 'middle'},
        {title: '', field: 'reservationsId', visible: false, align: 'center', valign: 'middle'},
        {title: '客户姓名', field: 'customerName', align: 'center', valign: 'middle', sortable: true},
        {title: '手机号码', field: 'customerPhone', align: 'center', valign: 'middle', sortable: true},
        {title: '门店', field: 'outpatientName', align: 'center', valign: 'middle', sortable: true},
        {title: '操作人', field: 'person', align: 'center', valign: 'middle', sortable: true},
        {title: '建档人', field: 'name', align: 'center', valign: 'middle', sortable: true},
        {title: '审核详情', field: 'content', align: 'center', valign: 'middle', sortable: true},
        {title: '提交时间', field: 'createtime', align: 'center', valign: 'middle', sortable: true},
        {title: '备注', field: 'remarks', align: 'center', valign: 'middle', sortable: true},
        {title: '是否成功', field: 'succeed', align: 'center', valign: 'middle', sortable: true}
    ]
    return columns;
};

/**
 * 查询 回访详情列表
 */
ApprovalProcessAudit.search = function () {
    ApprovalProcessAudit.table.refresh({query: ApprovalProcessAudit.formParams()});
};


/**
 * 查询表单提交参数对象
 * @returns {{}}
 */
ApprovalProcessAudit.formParams = function () {
    var queryData = {};
    queryData['outpatientName'] = $("#outpatientName").val();  //门诊
    queryData['startTime'] = $("#startTime").val();
    queryData['endTime'] = $("#endTime").val();
    return queryData;
}

$(function () {
    document.getElementById("startTime").value = myDate.getFullYear() + "-" + month + "-" + day + " " + "00:00:00";
    document.getElementById("endTime").value =myDate.getFullYear() + "-" + month + "-" + day + " " + "23:59:59";
    //初始化下拉到店门诊列表
    $.post(Feng.ctxPath + "/outpatientManagement/getList", function (data) {
        var txt = '<option value="">--请选择到店门诊--</option>';
        console.log(data);
        for (var i = 0; i < data.length; i++) {
            txt += '<option value="' + data[i].simplename + '">' + data[i].simplename + '</option>';
        }
        document.getElementById('outpatientName').innerHTML = txt;
        //状态单选
        var seleteooutpatientName = $('#outpatientNameValue').val();
        if (seleteooutpatientName != "") {
            $("#outpatientName option[value=" + seleteooutpatientName + "]").attr("selected", "selected");
        }
    }, "json");

    var defaultColunms = ApprovalProcessAudit.initColumn();
    var table = new BSTable(ApprovalProcessAudit.id, "/approvalProcessLog/list", defaultColunms);
    table.setPaginationType("server");
    table.setQueryParams(ApprovalProcessAudit.formParams());
    ApprovalProcessAudit.table = table.init();
    ApprovalProcessAudit.search();

    //采用定时器监听 时间内容是否变化
    var oldStartValue = $("#startTime").val();
    var oldEndtimeValue = $("#endTime").val();
    setInterval(
        function () {//定时执行方法内容
            if ($("#startTime").val() != oldStartValue || $("#endTime").val() != oldEndtimeValue) {//如果时间发生变化，就触发查询事件
                ApprovalProcessAudit.search();
                //如果值发生变化之后，把最新的值赋值到老的变量里面
                oldStartValue = $("#startTime").val();
                oldEndtimeValue = $("#endTime").val();
            }
        }, 500);
});
